﻿using AutoMapper;
using MediatR;
using StoreIModels;
using StoreISet.Applicationes.Command;
using StoreRepositorys.Interface;

namespace StoreISet.Applicationes.CommandHandler
{
    /// <summary>
    /// 上传图片修改
    /// </summary>
    public class PictureUpdateCommandler : IRequestHandler<PictureUpdateCommand, int>
    {
        public readonly IPictureRepository _pictureRepository;
        public readonly IMapper _mapper;
        public PictureUpdateCommandler(IPictureRepository pictureRepository, IMapper mapper)
        {
            _pictureRepository = pictureRepository;
            _mapper = mapper;
        }

        public async Task<int> Handle(PictureUpdateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                PictureModel model = _mapper.Map<PictureModel>(request);
                return await _pictureRepository.Updateasync(model);
            }
            catch (Exception)
            {

                throw;
            }
            
        }
    }
}
